package com.kelaite.procurement.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.kelaite.procurement.entity.TSalesOrder;

public interface SalesOrderRepository extends JpaRepository<TSalesOrder, Long> {

	public TSalesOrder findBySalesOrderNo(String salesOrderNo);
	
	@Modifying
	@Query(value = "update t_sales_order o set o.evaluationTotalDesc =:evaluationTotalDesc,o.evaluationScore4 =:evaluationScore4, o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy where o.id =:id")
	public int updateSalesOrderEstimate(@Param("id") Long id,
			@Param("evaluationTotalDesc") String evaluationTotalDesc,
			@Param("evaluationScore4") Double evaluationScore4,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);
	
	
	@Modifying
	@Query(value = "update t_sales_order o set o.evaluationTotalDesc =:evaluationTotalDesc,o.evaluationScore2 =:evaluationScore2,o.evaluationScore3 =:evaluationScore3,o.evaluationScore4 =:evaluationScore4,o.evaluationScore5 =:evaluationScore5, o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy where o.id =:id")
	public int updateSalesOrderEstimateManyGrade(@Param("id") Long id,
			@Param("evaluationTotalDesc") String evaluationTotalDesc,
			@Param("evaluationScore4") Double evaluationScore2,
			@Param("evaluationScore4") Double evaluationScore3,
			@Param("evaluationScore4") Double evaluationScore4,
			@Param("evaluationScore4") Double evaluationScore5,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);
	
	@Query(value = "select * from t_sales_order where  company_id =?1 order by gmt_create_time desc", nativeQuery = true)
	public List<TSalesOrder> getSalesOrderOrderByTime(Long companyId);
	
	@Query(value = "select * from t_sales_order where  company_id =?1 order by evaluation_time desc", nativeQuery = true)
	public List<TSalesOrder> getSalesOrderOrderByEvaluationTime(Long companyId);
}
